﻿using Inovout.Data.Domain;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace KuaJing.Organization.Domain
{
    partial class OrganizationUnit : TreeDataObject<OrganizationUnit>
    {
        public OrganizationUnit()
        {
            this.Employees = new HashSet<Employee>();
            this.Positions = new HashSet<Position>();
        }
        [DataProperty("名称", DataType.Text, null, true, 2, 50)]
        public virtual string Name { get; set; }
        [DataProperty("简称", DataType.Text, null, true, 1, 50)]
        public virtual string ShortName { get; set; }

        private string namePath;
        public virtual string NamePath
        {
            get
            {
                return namePath ?? "/" + this.Name;
            }
        }
        private OrganizationUnit parent;
        [DataProperty("上级部门", DataType.Text, null, false, null, null)]
        [Select(SelectType.ComboTree, "Name")]
        public override OrganizationUnit Parent
        {
            get { return parent; }
            set
            {
                parent = value;
                namePath = "/" + this.Name;
                if (parent != null)
                {
                    namePath = parent.NamePath + namePath;
                }
            }
        }

        public virtual Employee Leader { get; set; }

        public virtual ISet<Employee> Employees { get; set; }

        public virtual ISet<Position> Positions { get; set; }


    }
}
